﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BUS;
using DTO;
namespace GUI
{
    
    public partial class FormChonSanPhamMini : Window
    {

        public string tensp;
        public int masp;
        public int cv;
        public double dg;
        public FormChonSanPhamMini()
        {
            InitializeComponent();
            hoiThoat = false;           
        }

        private void FormChonSanPhamMini_Load(object sender, EventArgs e)
        {
            List<SanPhamDTO> ds = new List<SanPhamDTO>();
            SanPhamBUS bus = new SanPhamBUS();
            ds = bus.LayDSSP();
            dataGridViewDSSP.Rows.Clear();
            for (int i = 0; i <= ds.Count - 1; i++)
            {
                dataGridViewDSSP.Rows.Add(ds[i].MaSP, ds[i].TenSP,ds[i].DonGiaTV, ds[i].DonGiaKL,ds[i].DiemCV,ds[i].DonGiaTV,ds[i].QuyCach,ds[i].DVT,ds[i].SLTon);
            }
        }
               private void txtTim_TextChanged(object sender, EventArgs e)
        {
            List<SanPhamDTO> ds = new List<SanPhamDTO>();
            SanPhamBUS bus = new SanPhamBUS();
            if (this.txtTim.Text.Trim().Length != 0)
            {
                ds = bus.TimSanPham(txtTim.Text.Trim());
                if (ds.Count > 0)
                {
                    dataGridViewDSSP.Rows.Clear();
                    for (int i = 0; i <= ds.Count - 1; i++)
                    {
                        dataGridViewDSSP.Rows.Add(ds[i].MaSP, ds[i].TenSP, ds[i].DonGiaTV, ds[i].DonGiaKL, ds[i].DiemCV, ds[i].DonGiaTV, ds[i].QuyCach, ds[i].DVT, ds[i].SLTon);
                    }
                }
                else
                {
                    //MessageBox.Show(this, "Không tìm thấy!", "Thông báo!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    FormChonSanPhamMini_Load(null, null);
                    return;
                }
            }
            else
            {
               // MessageBox.Show(this, "Nhập tên sản phẩm cần tìm!", "Thông báo!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }            
            
        }

               private void button1_Click(object sender, EventArgs e)
               {
                   int k = dataGridViewDSSP.CurrentRow.Index;
                   masp = int.Parse(dataGridViewDSSP[0, k].Value.ToString());
                   tensp = dataGridViewDSSP[1, k].Value.ToString();
                   dg = double.Parse(dataGridViewDSSP[2, k].Value.ToString());
                   cv = int.Parse(dataGridViewDSSP[4, k].Value.ToString());
                   this.Close();
               }


    }
}
